package com.group.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.pojo.User;
import com.group.pojo.UserNumber;
import com.group.service.UserService;
import com.group.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author group
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/group/user")
public class UserController {

    @Autowired
    private UserService userService;


    @ApiOperation(value = "查询全部用户表数据")
    @RequestMapping("/findAllUser")
    public R findAllUser(User user, Integer pageNo, Integer pageSize){
        if(pageNo==null){
            pageNo = 1;
        }
        if(pageSize==null){
            pageSize = 5;
        }
        //启动分页
        PageHelper.startPage(pageNo,pageSize);
        List<User> list = userService.findAllUser(user);
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return R.ok().data("pageinfo",pageInfo);
    }


    @ApiOperation("添加用户表内容")
    @PostMapping("/addUser")
    public R addUser(@RequestBody User user){
        boolean flag = userService.addUser(user);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation("删除用户表内容")
    @GetMapping("/delUser")
    public R delUser(User user){
//        user.setUserid(1);
        boolean flag = userService.deleteUser(user);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation("修改用户表内容")
    @RequestMapping("/updateUser")
    public R updateUser(@RequestBody User user){
//        user.setAccountnumber("1234567");
//        user.setPassword("1234");
//        user.setNickname("mackcl");
//        user.setName("有点名儿");
//        user.setStudenid("201924113321");
//        user.setTelephone("14785236547");
//        user.setSex(1);
//        user.setEmail("654987321@qq.com");
//        user.setUsercategory(1);
//        user.setDeletedstate(0);
//        user.setUserid(3);
        boolean flag = userService.updateUser(user);
        return flag ? R.ok() : R.error();
    }

}

